package wang.aweb.childcar.controller.management;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import wang.aweb.childcar.common.ApiRestResponse;
import wang.aweb.childcar.exception.CarException;
import wang.aweb.childcar.exception.CarExceptionEnum;
import wang.aweb.childcar.model.pojo.WqPage;
import wang.aweb.childcar.model.query.MemberParam;
import wang.aweb.childcar.service.MemberService;

import java.util.Map;

@RestController
@RequestMapping("/management/member/")
public class MemberController {
    @Autowired
    private MemberService memberService;
    @ApiOperation("获取用户列表")
    @PostMapping("list")
    public ApiRestResponse list(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit, @RequestBody MemberParam memberParam){
        PageInfo pageInfo=memberService.selectList(page,limit,memberParam);

        WqPage wqPage=new WqPage(pageInfo.getTotal(),pageInfo.getList());
        return ApiRestResponse.success(wqPage);
    }
    @PostMapping("setMoney")
    public ApiRestResponse setMoney(@RequestBody Map reqMap){
        if (StringUtils.isEmpty(reqMap.get("addMoney").toString())) {
            throw new CarException(CarExceptionEnum.MONEY_NOT_NULL);
        }
        Integer id=Integer.valueOf((String) reqMap.get("id"));
        Integer addMoney=Integer.valueOf(reqMap.get("addMoney").toString());
        memberService.sysAddMoney(id,addMoney);
        return ApiRestResponse.success();
    }
    @PostMapping("del")
    public ApiRestResponse del(@RequestBody Map reqMap){
        return ApiRestResponse.success();
    }
}
